package com.yukefms.rule.formula.basis;

import com.yukefms.engine.running.MatchedStatus;
import com.yukefms.engine.running.RunningContext;
import com.yukefms.jointpoint.BodyPointCloud;
import com.yukefms.jointpoint.GeometryAdaptorForPointCalculator;
import com.yukefms.jointpoint.GeometryRelations;
import com.yukefms.jointpoint.TolerantEpsilon;
import com.yukefms.rule.formula.interfaces.AbstractStaticBAFormula;
import com.yukefms.rule.formula.interfaces.StaticBAFormula;

/**
 * @Description
 * @Author Ping
 * @Date 2021/7/17 17:45
 **/
public class HorizonalBelowFormula extends AbstractStaticBAFormula implements StaticBAFormula {

    private String jointType1 ;
    private String jointType2 ;
    private double belowValue ;

    public HorizonalBelowFormula() {
    }

    public HorizonalBelowFormula(final String jointType1, final String jointType2) {
        super(jointType1, jointType2);
        this.jointType1 = jointType1;
        this.jointType2 = jointType2;
        this.belowValue = TolerantEpsilon.MOVING_LENGTH_EPSILON ;
    }

    public HorizonalBelowFormula(final String jointType1, final String jointType2, double belowValue) {
        super(jointType1, jointType2);
        this.jointType1 = jointType1;
        this.jointType2 = jointType2;
        this.belowValue = belowValue ;
    }

    @Override
    public MatchedStatus matched(BodyPointCloud bodyPointCloud, RunningContext context) {
        if (GeometryRelations.isHorizonalBelow(bodyPointCloud.getPosition(jointType1),
                bodyPointCloud.getPosition(jointType2), this.belowValue))
        {
            // if has successor , then pass to the next formula.
            if (this.successor != null) {
                return this.successor.matched(bodyPointCloud, context);
            } else {
                return MatchedStatus.TRUE;
            }
        }
        // if does not matched
        return MatchedStatus.FALSE;
    }


}
